home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / icalc / docs / advancedguide next >
Text File  |  1995-03-18  |  23KB  |  714 lines

  1. =============================================================================
  2.  
  3.     icalc - a complex-number expression language
  4.  
  5.     (C) 1991, 1992 Martin W. Scott. All Rights Reserved.
  6.  
  7.     Version 2.1
  8.  
  9. =============================================================================
  10.  
  11.     Advanced Guide
  12.  
  13. =============================================================================
  14.  
  15. This document describes the more advanced features of icalc, including
  16. programming constructs and array manipulation, as well as some information
  17. that was left out of the User Guide for clarity and continuity.
  18.  
  19. The syntax used in icalc is closely related to that of C, with many
  20. exceptions. Information/warnings specifically for people who are
  21. familiar with C will be indicated by lines prefixed with 'C:'.
  22.  
  23. Parentheses and braces will sometimes be used in examples where they
  24. don't strictly need to be, due to operator precedence rules. They are
  25. included for clarity. (NB: A table detailing relative precedences is in
  26. Appendix 1 of the User Guide.)
  27.  
  28.  
  29.  
  30. Numbers
  31. -------
  32. Icalc can read and display numbers in any base from 2 to 36. The most
  33. common bases used are 10 (almost always), 2 (binary) and 16 (hexadecimal).
  34. For bases greater than 10, the letters from A to Z (upper or lower-case)
  35. are used for the 'digits' 11 to 35. If you don't know what a number-base
  36. is, you may skip this section.
  37.  
  38. When you input a number, icalc assumes it is decimal unless indicated
  39. otherwise. To inform icalc that you are entering a binary number, prefix
  40. it with a percent sign '%'. Similarly, to denote a hexadecimal number,
  41. use a '$' prefix. (Note that there should be no space between the prefix
  42. and the number). For any other base, you should precede the number with
  43. its base, a letter 'r' (in lower case) followed by the number itself.
  44.  
  45. Examples:
  46.     
  47.     255        - (a) decimal representation of number 255
  48.     %11111111    - binary representation of number 255
  49.     $FF        - hexadecimal representation of number 255
  50.     3r100110    - base-3 representation of number 255
  51.     36r73        - base-36 representation of number 255
  52.  
  53. Sometimes it is convenient to use scientific notation when representing
  54. very large or small numbers. Usually, the letter 'e' denotes that an
  55. exponent is given, as for example in 1e10 (a 1 followed by 10 zeros).
  56. However, for bases >= 15, 'e' is a digit. I am unaware of any standard
  57. convention in such cases, so opted to use the '@' character, which can be
  58. used with any base (you may still use 'e' for any base < 15 though).
  59.  
  60. The exponent should be entered in the SAME BASE AS THE GIVEN NUMBER, and
  61. icalc displays numbers using this convention also (this seems the
  62. logical and consistent way to do things).
  63.  
  64. More Examples:
  65.  
  66.     1e5        - (a) decimal representation of the number 10000
  67.     %101e11        - binary representation of the number 40
  68.               (%101 = 5, %11 = 3, so %101e11 = 5 * 2^3)
  69.     8r7e7        - octal representation of the number 14680064
  70.               (8r7 = 7, so 8r7e7 = 7 * 8^7)
  71.     $1@10        - hexadecimal representation of the number 16^16
  72.  
  73. When icalc displays a number using scientific notation, it always
  74. explicitly shows the sign of its exponent, eg. entering 1e30 would
  75. produce 1e+30.
  76.  
  77. Fractions are input in the usual way as for decimal numbers. Thus
  78.  
  79.     $FF.FF
  80.  
  81. represents the number 15*16 + 15*1 + 15/16 + 15/(16^2), whilst
  82.  
  83.     %101.101
  84.  
  85. represents the number 1*4 + 0*2 + 1*1 + 1/2 + 0/4 + 1/8.
  86.  
  87. Note that to convert from one base to another, it is not enough just to
  88. convert each of the integer fraction and exponent parts separately. But
  89. anyway, you can use icalc for all base conversions you might want.
  90.  
  91. To specify which base icalc should display numbers, use the builtin
  92. outbase(n) - this affects all numbers output, except array indices output
  93. with the display() builtin (see the section on  arrays below).
  94.  
  95. The display routine in icalc prints a number to a certain number of
  96. significant digits. This is 12 by default, but may be changed by the
  97. prec() builtin. Entering prec(n) sets the number of significant digits
  98. to n. n must lie in the range 1 to 55. prec() returns the last answer
  99. (ans) so that you can see the effect immediately. It allows values up to
  100. 55 only for representations in lower bases -- you don't get 55 digits of
  101. precision using decimal representations. To save time, the functions
  102. bin(), oct(), dec() and hex() are defined in the 'icalc.init' file for
  103. your use. They set respectively base 2, 8, 10 and 16, as well as setting
  104. a suitable precision for numbers to be displayed at.
  105.  
  106. Generally speaking, icalc doesn't consider leading zeros in a fraction as
  107. significant, e.g. in the number 0.0012, the significant part is 12. If a
  108. fraction has more than the set number of significant digits, it is
  109. displayed in scientific notation. Whilst this gives the desired number
  110. of significant digits, it is sometimes aesthetically unpleasing.
  111. Therefore, a fixed number of leading zeros are condidered significant,
  112. by default 4. This can be altered by the sigzeros(n) builtin. Note that
  113. if n is zero, numbers will always be displayed with the set number of
  114. significant digits.
  115.  
  116. To demonstrate what I mean, here's an example (assuming default settings):
  117.  
  118.     > PI
  119.         3.14159265359
  120.     > PI/10
  121.         0.31415926536
  122.     > PI/1000
  123.         0.00314159265
  124.     > PI/100000    # gives rise to 5 leading zeros
  125.         3.14159265359e-5
  126.     > sigzeros(5)
  127.         0.00003141593
  128.         ^ ^^^^
  129.         these 5 zeros are considered significant
  130.  
  131.  
  132. And finally, a small example on rounding errors. Recall from the user
  133. guide the example expression
  134.  
  135.     sin(2*x) - 2*sin(x)*cos(x)
  136.  
  137. where x had the value 4, and the expression returned 2.22044604925e-16.
  138. This looks at first like a rather strange error, but turns out not to be.
  139. The following sample session shows why:
  140.  
  141.     > x = 4
  142.         4
  143.     > sin(2*x) - 2*sin(x)*cos(x)
  144.         2.22044604925e-16
  145.     > bin()  # sets prec to 35
  146.         %1e-110100
  147.     > prec(55)  # we can see what's happened, but let's see better
  148.         %0.0000000000000000000000000000000000000000000000000001
  149.  
  150. and we see that the apparently strange error is actually caused by one
  151. bit in the computer's (binary) representation of the result. Not at all
  152. strange...
  153.  
  154.  
  155.  
  156. Principal value ranges (PVRs)
  157. -----------------------------
  158. The PVRs are defined for the inverse trigonometric functions as follows:
  159.  
  160.     asin:   if u + iv = asin(z), then
  161.         -PI/2 <= u <= PI/2  if v >= 0
  162.         -PI/2  < u  < PI/2  if v < 0
  163.  
  164.     acos:   if u + iv = acos(z), then
  165.         0 <= u <= PI    if v >= 0
  166.         0  < u  < PI    if v < 0
  167.  
  168.     atan:   if u + iv = atan(z), then
  169.         -PI/2 < u < PI/2    
  170.  
  171.  
  172.  
  173. Additional assignment operators
  174. -------------------------------
  175. As well as the standard = operator, icalc comes with some others both to
  176. improve readability and efficiency of functions. They are:
  177.  
  178.     a += b        equivalent to   a = a+b
  179.     a -= b        equivalent to   a = a-b
  180.     a *= b        equivalent to   a = a*b
  181.     a /= b        equivalent to   a = a/b
  182.  
  183. It is faster to use these operators rather than the explicit operations.
  184.  
  185. C: The ++ and -- operators are not included, since the evaluation method
  186. C: cannot handle pre- and post- operations rigorously.
  187.  
  188.  
  189.  
  190. Relational operators
  191. --------------------
  192. These operators allow comparisons between two values. Of course, the set of
  193. complex numbers has no logical ordering; all relational comparisons are
  194. done with real parts only, but equivalence comparisons are done on both
  195. real and imaginary parts. This system allows for people who are writing
  196. real-number applications to once again completely ignore complex numbers. 
  197. To use relational operators on imaginary parts, you must use Im().
  198.  
  199. Relational operators are used in BOOLEAN expressions; these expressions can
  200. take one of two values: TRUE (1.0) and FALSE (0.0). In the table below, a and
  201. b represent numerical expressions, and E and F represent boolean expressions.
  202.  
  203.  
  204.     BOOLEAN EXPRESSION    TRUE if and only if
  205.  
  206.     a == b            a has same value as b 
  207.     a != b            a has different value to b
  208.     a > b            value of a greater than that of b
  209.     a >= b            value of a greater than or equal to that of b
  210.     a < b            value of a less than that of b
  211.     a <= b            value of a less than or equal to that of b
  212.  
  213.     E && F            E is TRUE and F is TRUE
  214.     E || F            E is TRUE or F is TRUE
  215.  
  216. Examples:
  217.  
  218.     5 > 3            TRUE
  219.     2 != 2            FALSE
  220.     2 + 10i >= 20 + i    FALSE  (imaginary parts are ignored)
  221.     3 > 2i            TRUE   (2i has real part 0.0)
  222.     -3 > 2i            FALSE
  223.  
  224. and as always, consider rounding errors when comparing:
  225.  
  226.     PI == atan(1)*4        FALSE
  227.  
  228.  
  229. The logical operators && and || use short-circuit evaluation. This means
  230. that they only evaluate their right-hand argument if the result of the
  231. operation is still undetermined. An example will clarify.
  232.  
  233.     (5 > 3) && (6 < 8)  Needs to evaluate E and F
  234.        E          F
  235.  
  236.     (5 > 8) && (6 < 8)  E evaluates to FALSE, so expression is false,
  237.        E          F     and so F is not evaluated.
  238.  
  239. This has some important implications, for example if (boolean) expression F
  240. contained an assignment expression, then it might not be evaluated
  241. depending on expression E.
  242.  
  243. I have found that short-circuit evaluation is the most convenient way of
  244. handling && and ||. Some languages don't guarantee even order of evaluation
  245. (e.g. Pascal) and this can sometimes create harder to read programs.
  246.  
  247. One other operator is present in icalc, as a shorthand for if-then-else
  248. statements, the ternary operator, '?:'. This has the form
  249.  
  250.     E ? a : b
  251.  
  252. and reads as "if E is true then the value of the ternary operator is a,
  253. otherwise it's b". Only one of a or b is evaluated. An example will clarify:
  254.  
  255.     (x >= 2) ? (x -= 1) : (x = 100)
  256.  
  257. means "If x is greater than 2, then subtract one from x, otherwise assign the
  258. value 100 to x".
  259.  
  260. Numerical expressions can stand in for boolean expressions. A numerical
  261. expression has boolean value TRUE if its real part is non-zero, and FALSE
  262. if it is zero.  So, for example, if x is purely real,
  263.  
  264.     y = (x ? 1 : 0)            (*)
  265.  
  266. is equivalent to
  267.  
  268.     y = (x != 0 ? 1 : 0)        (**)
  269.  
  270. and assigns 1 to y if x is non-zero, and 0 to y if x is zero.
  271.  
  272. Do remember that imaginary parts are ignored in comparisons. In x were
  273. purely imaginary, (*) and (**) would assign 1 and 0 respectively to y (i.e.
  274. they would behave differently).
  275.  
  276.  
  277.  
  278. Arrays 
  279. ------
  280. icalc has simple one-dimensional arrays, which can only be declared outside
  281. function definitions. Array elements are referenced using square brackets,
  282. and the first element by default has index 1, but this can be changed.
  283.  
  284. C: This is in contrast to C, where indices start at zero. The system used in
  285. C: icalc is more suited to many mathematical applications.
  286.  
  287. To create an array a, use the statement
  288.  
  289.     array a[dimension]  # creates cleared array
  290.  
  291. The dimension should be a positive integer. It may be an expression, which
  292. will have its imaginary part discarded, and rounded DOWN to an integer.
  293. All elements initially hold the value zero.  You may optionally pre-assign
  294. the array at creation by using
  295.  
  296.     array a[dimension] = { expr1, expr2, ... exprP }
  297.  
  298. This second form allows pre-initialization of elements 1 to P;
  299. P must be <= dimension (so can partially initialise array).
  300.  
  301. Arrays are referenced by a[expr], the index being calculated as the
  302. real part of <expr> rounded to the NEAREST integer.
  303. NB: in version 2.0, the index was calculated as the floor of the real
  304. NB: value.
  305.  
  306. Range checking is performed, and user will be informed of invalid array
  307. references. 
  308.  
  309. As already mentioned, arrays must be created at the top level, ie. NOT in
  310. function definitions.  In this version, there are NO local (to function)
  311. arrays.
  312.  
  313. There are a few builtin functions to help you manuipulate arrays:
  314.  
  315.     arraybase(n)    index n now denotes 1st element of all arrays
  316.     sizeof(a)    returns number of elements in a,
  317.     resize(a,n)    resizes a to n elements,
  318.     display(a)    prints a list of elements in a.
  319.  
  320. The latter two functions return a value 1 by convention. If you resize()
  321. an array to make it larger, the new elements created will NOT be set to
  322. zero.
  323.  
  324. The arraybase routine lets you change how arrays are indexed. As already
  325. stated, the first element by default has index 1. Using arraybase, any
  326. non-negative integer may be used (primarily zero, as in C). arraybase(n)
  327. returns the old base, so you can write functions which set things up how
  328. the like at the start, and restore them when they return. Also, the
  329. constant ABASE holds the current setting, so functions can also use that
  330. to handle whatever preference is set. arraybase returns the value -1 if
  331. given an invalid argument.
  332.  
  333. In the example scripts contained in the distribution of icalc, I have
  334. NOT provided for array bases other than 1, except in zroots.ic, where
  335. the routines change and restore the arraybase to suit their needs. If
  336. you wish to use the other routines with a different base, you will have
  337. to modify them using one of the above methods (I didn't want to confuse
  338. the examples with excess baggage).
  339.  
  340. Here is a small example session to demonstrate some features:
  341.  
  342.     > array a[3] = { 1, 2, 3 }
  343.     > display(a)
  344.         a[1] =  1
  345.         a[2] =  2
  346.         a[3] =  3
  347.         1
  348.     > a[2] = 12
  349.         12
  350.     > a[3] < a[2] ? x = 3 : x = 2
  351.         3
  352.     > sizeof(a)
  353.             3
  354.     > resize(a,4)      # a[4] will contain garbage
  355.         1
  356.     > a[4] = 4
  357.         4
  358.     > display(a)
  359.         a[1] =  1 
  360.         a[2] =  12
  361.         a[3] =  3 
  362.         a[4] =  4 
  363.         1        
  364.     > resize(a,2)
  365.         1
  366.     > display(a)
  367.         a[1] =  1 
  368.         a[2] =  12
  369.  
  370.  
  371.  
  372. Blocks
  373. ------
  374. Blocks are a way to group expressions so they are treated as one big
  375. expression. They have the form
  376.  
  377.     { expr1; expr2; ... exprN; }
  378.  
  379. and the value of a block is the value of its last expression, exprN.  The
  380. expressions may also be separated by newlines (as many as you like)instead.
  381. Blocks can have as little as one expression, which is sometimes useful for
  382. easier-to-read source code.
  383. Examples:
  384.  
  385.     > { a=3;b=2;a*b;}
  386.         6
  387.     > {
  388.     >  a = 2
  389.     >  b = 3
  390.     >  c = 4; d = 5
  391.     >  a*b*c*d
  392.     > }
  393.         120
  394.  
  395. Blocks are principally of use with control-flow constructs, and further
  396. (more useful) examples are given below.
  397.  
  398.  
  399.  
  400. Control-flow constructs
  401. -----------------------
  402. A number of control-flow constructs are available, closely modelled on those
  403. of the C language.
  404.  
  405. C: C is a free-form language, and spacing can appear anywhere in C source.
  406. C: icalc however, is free-form only per-line, due to its interactive nature;
  407. C: icalc must be able to determine when an expression stops, so that it knows
  408. C: when to print a result. Care should be taken to follow icalc's conventions.
  409.  
  410. Where newlines are shown, they are optional; where they are not shown, they
  411. are not permitted, and will either cause a syntax error, or incorrect
  412. behaviour. All horizontal spacing is optional, and used for clarity.
  413.  
  414. Below, Bexpr denotes a boolean expression, Texpr is the expression
  415. evaluated if Bexpr is TRUE, and Fexpr the expression evaluated if Bexpr is
  416. FALSE.
  417.  
  418. if-else
  419. -------
  420. A construct common to almost all programming languages is the if-statement.
  421. In icalc, it has the form
  422.  
  423.     if (Bexpr)
  424.         Texpr
  425.  
  426. or with an else-clause,
  427.  
  428.     if (Bexpr) 
  429.         Texpr else
  430.             Fexpr 
  431.  
  432. Note that 'else' keyword must be on same line as Texpr. If it were allowed
  433. on the next line, non-else-clause if-statements would cause problems in
  434. interactive use. It sometimes looks ungainly, but blocks may be used to
  435. spread it over lines, as shown below.
  436. Some examples:
  437.  
  438.     if (a == 2)
  439.         b = a+1
  440.  
  441.     if (a == 2)
  442.         b = a+1 else b = a-1
  443.  
  444.     if (a == 2) {
  445.         b = a+1
  446.     } else {
  447.         b = a-1
  448.     }
  449.  
  450. while-loop
  451. ----------
  452. This is an iteration construct, of the form
  453.  
  454.     while (Bexpr)
  455.         Texpr
  456.  
  457. and reads as "while the boolean expression Bexpr evaluates to TRUE, evaluate
  458. Texpr".  The following example calculates n!, where n is an integer:
  459.  
  460.     f = 1; n = 10;      # initialize f, n
  461.     while (n > 0)       # n not yet zero, so still work to do
  462.     {
  463.         f *= n      # multiply f by n
  464.         n -= 1      # decrement n
  465.     } 
  466.     # f now holds value of 10!
  467.  
  468. do-while-loop
  469. -------------
  470. This is another iteration construct, closely related to a while-loop, with
  471. the distinction that the loop-test (the boolean expression governing the
  472. loop's operation) is performed AFTER the body of the loop. It has the form
  473.  
  474.     do 
  475.         Texpr
  476.     while (Bexpr)
  477.  
  478. Texpr is evaluated first; then, if Bexpr is TRUE, Texpr is re-evaluated and
  479. Bexpr tested again; and so on...
  480.  
  481. Whereas with a while-loop, the Texpr may never be evaluated (if Bexpr
  482. evaluates to FALSE initially), in a do-while-loop, Texpr is always
  483. evaluated at least once.
  484. An example -- sin() applied five times to a value x:
  485.  
  486.     n = 5; s = x        # n is number of times to apply sin()
  487.     do {
  488.         s = sin(s)  # apply sin()
  489.         n -= 1      # decrement n
  490.     } while (n >= 1)    # more to do?
  491.  
  492.     # s has value sin(sin(sin(sin(sin(x)))))    (sin 5 times)
  493.  
  494. for-loop
  495. --------
  496. The for-loop in icalc is like that of the C language, and has the form
  497.  
  498.     for (initexpr; condexpr; incexpr)
  499.         expr
  500.  
  501. initexpr, condexpr and incexpr are all optional (but semi-colons ; are not).
  502. The for loop is a shorthand for
  503.  
  504.     initexpr
  505.     while (condexpr)
  506.     {
  507.         expr
  508.         incexpr
  509.     }
  510.  
  511. Example:
  512.     array a[100]
  513.     for (n = sizeof(a); n > 0; n -= 1)
  514.         a[n] = 1
  515.  
  516.     # all elements of a are 1.
  517.  
  518. C: icalc's for-loop is not as flexible as C's; there is no comma operator,
  519. C: and initexpr, condexpr and incexpr can only be simple (not blocks).
  520.  
  521.  
  522.  
  523. Function definitions
  524. --------------------
  525. The User Guide explains how to define simple functions. As mentioned there,
  526. you can use a block as the body of a function (e.g. rec2pol definition).  
  527. There are more sophisticated facilities available, which provide a similar
  528. functionality to that of C. However, for a number of reasons, the syntax
  529. used in icalc differs widely from C's.
  530.  
  531. Function parameters may be one of four types:
  532.  
  533.     VALUE:        These are the normal parameters that we've been using
  534.             all along.
  535.  
  536.     POINTER:    These are like variable parameters in Pascal.
  537.             Denoted in parameter list by *.
  538.  
  539.     ARRAY:        These are passed by reference, NOT value, as in C
  540.             Denoted by @.
  541.  
  542.     EXPR:        Strange one this. It's like a pointer to a function,
  543.             but more/less flexible depending on how you look
  544.             at it. Example below will clarify.
  545.             Denoted by ~.
  546.  
  547. Note that, although a function cannot have local arrays, the array
  548. reference parameter IS local, and completely independent of arrays defined
  549. globally.
  550.  
  551. Functions may also have local variables, introduced by a statement
  552.  
  553.     local v1,v2,v3,...,vN
  554.  
  555. within the function body.  There can be as many local declarations as you
  556. like. All local variables behave like VALUE variables - there are no local
  557. pointers or arrays as yet.
  558.  
  559. C: local declarations apply to the function they appear in; there are no
  560. C: block-local variables.
  561.  
  562. The following small suite of functions demostrate the ideas above.
  563.  
  564.     # swaps values in variables a and b.
  565.     func swap(*a,*b) = {    # a and b are pointers
  566.         local tmp    # only expressions in swap() know about tmp
  567.  
  568.         tmp = a
  569.         a = b
  570.         b = tmp
  571.     }
  572.  
  573.     x = 5; y = 7
  574.     swap(x,y)    # x now holds 7, y holds 5
  575.  
  576.  
  577.     # nexpr is an expression in (global) variable n
  578.     # a is an (arbitrary) array.
  579.     # fill evaluates Nexpr for every index n of array a, and places
  580.     # result in a[n].
  581.     func fill(@a, ~nexpr) = {
  582.         for (n = sizeof(a); n > 0; n -= 1)
  583.             a[n] = nexpr;    # just referencing nexpr causes
  584.                     # it to be evaluated.
  585.     }
  586.  
  587. The return value of a function is the value of the last expression evaluated.
  588. Sometimes it's inconvenient for this to be the case, so the return statement
  589. is provided. A line of the form
  590.  
  591.     return a
  592.  
  593. encountered anywhere during function evaluation will end the function call,
  594. returning the value of a.
  595.  
  596. I'm sure you will agree that these mechanisms allow many sophisticated
  597. operations to be performed by user-functions. The examples in this document
  598. are simple-minded for the most part, to give you the bare facts about what
  599. can be done. I have included many sample script-files containing one or more
  600. function definitions which are useful to a varying degree, and in some
  601. cases add very powerful extensions to icalc.
  602.  
  603.  
  604.  
  605. Script files
  606. ------------
  607. The script files include:
  608.  
  609.     array.ic    - utility routines for arrays
  610.     arraytest.ic    - tests routines defined in array.ic
  611.     bern.ic        - computes Bernoulli numbers
  612.     cheby.ic    - computes coefficients for Chebychev polynomials
  613.     gamma.ic    - gamma and related functions
  614.     gl.ic        - integration by 10-pt Gauss-Legendre quadrature
  615.     loop.ic        - demonstrates all looping constructs
  616.     poly.ic        - polynomial support routines
  617.     root.ic        - root-finding of functions
  618.     sort.ic        - routine to perform Shell sort on arrays
  619.     trig.ic        - some rarely used trig-functions
  620.     zroots.ic    - find all roots of a polynomial (real & complex)
  621.  
  622.     polint.ic     -
  623.     trapzd.ic      |
  624.     qtrap.ic       |- numerical integration routines
  625.     qsimp.ic       |      (see Integration.notes in Scripts directory).
  626.     qromb.ic      -
  627.  
  628.  
  629.  
  630. Undocumented commands
  631. ---------------------
  632. There is a 'clear' command, which deletes from memory a variable, array or
  633. function. However, care MUST be taken, since icalc does not check that the
  634. object being deleted is not referenced elsewhere (in a function). If it is
  635. referenced after it has been deleted, the system will more than likely
  636. crash. The command was only really added to delete large arrays which take
  637. up a lot of memory. You have been warned...  
  638.  
  639.     clear <symbol>
  640.  
  641.  
  642.  
  643. Caveats
  644. -------
  645. Assignment
  646. ----------
  647. When assigning variables within another expression, it is safer to
  648. enclose the assignment in parentheses, to ensure that the expression
  649. is evaluated correctly.
  650.  
  651. Defining functions in terms of other functions
  652. ----------------------------------------------
  653. A function is stored internally as a structure, and a reference to
  654. a function, f, from another, g, creates a pointer to the structure
  655. for f. Thus, changing f changes g also.
  656. An example will illuminate this:
  657.  
  658.     > func f(x) = x*x
  659.     > func g(x) = f(2*x)
  660.     > f(4)
  661.         16
  662.     > g(4)
  663.         64
  664.     > func f(x) = sqrt(x)      # changes behaviour of g
  665.     > f(4)
  666.         2
  667.     > g(4)
  668.         2.82842712
  669.  
  670. Therefore, you cannot use function definitions as a kind of function
  671. assignment.
  672.  
  673. Comparisons
  674. -----------
  675. Due to the inexactness of computer calculations, you must be careful
  676. when using comparison operators. Again, an example will illuminate:
  677.  
  678.     > j = 12*PI
  679.         37.69911184
  680.     > while j != 0 do {print(j); j = j-PI;}
  681.         37.69911184
  682.         34.55751919
  683.             :
  684.         3.14159265
  685.         -3.5527136e-15    <--- not quite zero
  686.         -3.14159265
  687.             :
  688.     etc.
  689.  
  690. The arrow points to the position where, because of rounding errors,
  691. j is not exactly zero, and the loop never terminates, since the
  692. condition j != 0 is always satisfied.
  693.  
  694. There are two ways to get round problems like this. You can use a >=
  695. operator, or, if comparison is with (theoretically) integral values,
  696. the int() function, which rounds its argument to the NEAREST integer.
  697.  
  698.  
  699.  
  700. Questions
  701. ---------
  702. I've tried to cover everything in a clear and precise way, but almost
  703. certainly have failed in some areas. If you have any questions about icalc,
  704. write to me and I'll respond as soon as I can. Addresses are in the User
  705. Guide.
  706.  
  707. Also, if you write any scripts which you feel other users may find useful
  708. (for example, routines applying to physics or astronomy calculations)
  709. please send them to me for inclusion with the next release of icalc.
  710.  
  711. Enjoy,
  712.  
  713.     Martin Scott.
  714.